// ==============================================================================================
// TabSetTreeNode.cs
//
// Created by: NI, 2007.03.27
// Revised by: NI, 2007.11.23
// ==============================================================================================
using System.Windows.Forms;
using RibbonExplorer.Entities;
using RibbonExplorer.InfoPanel;

namespace RibbonExplorer.Tree
{
  // ==============================================================================================
  /// <summary>
  /// This tree node represents a tab set in the tree.
  /// </summary>
  // ==============================================================================================
  public class TabSetTreeNode : OnDemandTreeNode, IInfoPanelSupport
  {
    #region Private fields

    private TabSet _TabSet;

    #endregion

    #region Lifecycle methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates the tree node instance.
    /// </summary>
    /// <param name="tabSet">Tab set instance for this tree node.</param>
    // --------------------------------------------------------------------------------------------
    public TabSetTreeNode(TabSet tabSet)
      : base(tabSet.Id)
    {
      _TabSet = tabSet;
      ImageKey = "Tabset";
      SelectedImageKey = ImageKey;
      Tag = _TabSet;
    }

    #endregion

    #region Public properties

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Get the tab set instance represented by this node.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public TabSet TabSet
    {
      get { return _TabSet; }
    }

    #endregion

    #region Overridden methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Handle the event when the tree node is fisrt time expanded.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    protected override void OnExpandFirstTime()
    {
      base.OnExpandFirstTime();
      _TabSet.LoadChildren();

      // --- Create contextual tab nodes
      foreach (ContextualRibbonTab tab in _TabSet.Tabs)
      {
        Nodes.Add(new ContextualTabTreeNode(tab));
      }
    }

    #endregion

    #region IInfoPanelSupport implementation

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates an infopanel instance for this tree node type.
    /// </summary>
    /// <param name="node">Tree node instance</param>
    /// <param name="navigationService">Navigation service instance</param>
    /// <returns>
    /// User control instance
    /// </returns>
    // --------------------------------------------------------------------------------------------
    public UserControl GetInfoPanelInstance(TreeNode node, INavigationSupport navigationService)
    {
      GenericInfoPanel control = new GenericInfoPanel(navigationService, node);
      control.HeaderText = "Tab set: " + node.Text;
      return control;
    }

    #endregion
  }
}
